'user strict'

const fs = require('fs')

class uploadFunc{
    constructor () {
        this.param = '/'
      }
    
      async post (c) {

        console.log("调用func接口");

        let f = c.getFile('logo')

        console.log(1111,f);


        //解析文件扩展名
        let ext_name = c.helper.extName(f.filename)
      
        //生成唯一文件名
        let fname = `${c.helper.makeName()}${ext_name}`

        let data = {
          openid:c.box.user.openid,
          appname:c.body.appName,
          funcname:c.body.funcName,
          imagename:fname
        }

        console.log(222,data);

        console.log(333,c.service.model);
    
        let data1 = await c.service.model.db_wxUserUpload.wxUserUploadFunc(data);

        //将图标移入文件夹
        await c.moveFile(f, `${c.service.publicPath}/usercreate/icon/${fname}`)

        //返回插入的这个功能的id
        c.send(data1,200)
  
      }

}

module.exports = uploadFunc